<?php
/**
 *  TinyMVC - TinyMVCSimpleContainer.class.php file
 * 
 * @author Adrian Wieczorek <adi(at)tinymvc(dot)org>
 * @package TinyMVC
 * @version $Id: TinyMVCSimpleContainer.class.php 3 2007-09-11 12:08:07Z adi3ek $
 * 
 */
 
/**
 * simple container implementation
 * @package TinyMVC
 */
class TinyMVCSimpleContainer {
	private $elements = array();
	
	/**
	 * add element to container
	 * @param string $key element key
	 * @param mixed $value element value
	 */
	public function addElement($key, $value) {
		$this->elements[$key] = $value;
	}
	
	/**
	 * Alias: {@link addElement()}
	 */
	public function add($key, $value) {
		$this->addElement($key, $value);
	}
	
	/**
	 * get element from container
	 * @param string $key element key
	 * @param mixed $nullValue return value for non-existent key
	 * @return mixed element
	 */
	public function getElement($key, $nullValue = null) {
		return $this->isKeyExists($key) ? $this->elements[$key] : $nullValue;
	}
	
	/**
	 * Alias: {@link getElement()}
	 */	
	public function get($key, $nullValue = null) {
		return $this->getElement($key, $nullValue = null);
	}
	
	/**
	 * remove element from container
	 * @param string $key element key
	 */
	public function remove($key) {
		unset($this->elements[$key]);
	}
	
	/**
	 * get all elements from container
	 * @return array list of elements
	 */
	public function getElements() {
		return $this->elements;
	}
	
	/**
	 * get number of elements in container
	 * @return int number of elements
	 */
	public function getElementsNum() {
		return count($this->elements);
	}
	
	/**
	 * check, whether or not element with given key exists
	 * @param string $key element key
	 * @return bool
	 */
	public function isKeyExists($key) {
		return array_key_exists($key, $this->elements);
	}	
}
